package com.itheima.reggie.utils;

/**
 * @author: Jetwang
 * @date: 2022/4/11 14:59
 * @description: BaseContextUtil 基于ThreadLocal封装的工具类，用于保存当前登录用户的id
 * @version: 1.0
 */
public class BaseContextUtil {
    private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();

    /**
     * 存放当前用户id
     * @param id
     */
    public static void setCurrentId(Long id) {
        threadLocal.set(id);
    }

    /**
     * 获取当前用户id
     * @return
     */
    public static Long getCurrentId() {
        return threadLocal.get();
    }

    /**
     * 移除当前用户id
     */
    public static void removeCurrentId() {
        threadLocal.remove();
    }
}
